package com.ad.pet.app.recharge;

import android.support.annotation.Nullable;
import android.widget.ImageView;
import android.widget.TextView;

import com.ad.pet.R;
import com.ad.pet.models.remote.account.order.PayMethod;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

/**
 * Created by SEELE on 2018/6/5.
 */

public class RechargeAdapter extends BaseQuickAdapter<PayMethod, BaseViewHolder> {
    public RechargeAdapter(@Nullable List<PayMethod> data) {
        super(R.layout.item_pay_way, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, PayMethod item) {
        ImageView iv_bank = helper.getView(R.id.iv_bank);
        TextView tv_bank_name = helper.getView(R.id.tv_bank_name);
        ImageView ivChose = helper.getView(R.id.ic_chose);

       iv_bank.setImageResource(item.getIcon());
        tv_bank_name.setText(item.getPayment_method());
        ivChose.setImageResource(item.isChose() ? R.drawable.ic_xizhi_gou : R.drawable.ic_unchose);




    }

    public PayMethod getChoseRecharge() {
        PayMethod recharge = null;
        for (int i = 0; i < mData.size(); i++) {
            if (mData.get(i).isChose()) {
                recharge = mData.get(i);
            }
        }
        return recharge;
    }

    public void setChoseRecharge(int position) {
        for (int i = 0; i < mData.size(); i++) {
            if (i == position) {
                mData.get(i).setChose(true);
            } else {
                mData.get(i).setChose(false);
            }
        }
        notifyDataSetChanged();
    }
}
